#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<int> a(n + 1);
    vector<int> last_pos(300005, 0);
    vector<long long> count(300005, 0);
    vector<long long> sum(300005, 0);
    long long ans = 0;
    
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    
    for (int i = 1; i <= n; i++) {
        int x = a[i];
        if (last_pos[x] == 0) {
            last_pos[x] = i;
            count[x]++;
        } else {
            sum[x] += count[x] * (i - last_pos[x] - 1);
            ans += sum[x];
            count[x]++;
            last_pos[x] = i;
        }
    }
    
    cout << ans << endl;
    return 0;
}